<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('学生信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>学号：</label>
                                <input type="text" name="studentNo"/>
                            </li>
                            <li>
                                <label>姓名：</label>
                                <input type="text" name="name"/>
                            </li>
<!--                            <li>-->
<!--                                <label>性别：</label>-->
<!--                                <input type="text" name="gender"/>-->
<!--                            </li>-->
                            <li>
                                <label>所属班级：</label>
<!--                                <input type="text" name="classId"/>-->
                                <select name="classId" class="form-control">
                                    <option value="">全部</option>
                                    <option th:each="class:${classes}" th:value="${class.classId}" th:text="${class.className}"></option>
                                </select>
                            </li>
                            <li>
                                <label>入学时间：</label>
                                <input type="text" class="time-input" placeholder="请选择入学时间" name="enrollmentDate"/>
                            </li>
                            <li>
                                <label>学生状态：</label>
                                <select name="status" th:with="type=${@dict.getType('sys_student_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="college:student:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="college:student:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="college:student:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="college:student:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-warning" onclick="$.table.exportTemplate()" shiro:hasPermission="college:student:exportTemplate">
                    <i class="fa fa-download"></i> 下载模板
                </a>
                <a class="btn btn-success" onclick="$.table.importExcel()" shiro:hasPermission="college:student:import">
                    <i class="fa fa-upload"></i> 导入
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('college:student:edit')}]];
        var removeFlag = [[${@permission.hasPermi('college:student:remove')}]];
        var gendersDatas = [[${@dict.getType('sys_user_sex')}]];
        var statusDatas = [[${@dict.getType('sys_student_status')}]];
        var prefix = ctx + "college/student";
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            exportTemplateUrl: prefix + "/exportTemplate",
            importUrl: prefix + "/import",
            modalName: "学生信息",
            columns: [{
                checkbox: true
            },
            {
                field: 'studentId',
                title: '学生ID',
                visible: false
            },
            {
                field: 'studentNo',
                title: '学号'
            },
            {
                field: 'name',
                title: '姓名'
            },
            {
                field: 'gender',
                title: '性别',
                formatter: function(value, row, index) {
                    return $.table.selectDictLabel(gendersDatas, value);
                }
            },
            // {
            //     field: 'classId',
            //     title: '所属班级'
            // },
            {
                field: 'className',
                title: '所属班级'
            },
            {
                field: 'enrollmentDate',
                title: '入学时间'
            },
            {
                field: 'status',
                title: '学生状态',
                formatter: function(value, row, index) {
                   return $.table.selectDictLabel(statusDatas, value);
                }
            },
            {
                field: 'remark',
                title: '备注'
            },
            {
                title: '操作',
                align: 'center',
                formatter: function(value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.studentId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.studentId + '\')"><i class="fa fa-remove"></i>删除</a>');
                    return actions.join('');
                }
            }]
           };
        $(function() {
            $.table.init(options);
        });
    // 为表格工具类添加下载模板方法
        $.table.exportTemplate = function() {
            var url = options.exportTemplateUrl;
            if (url) {
               $.get(url, {}, function(result) {
                if (result.code == 0) {
                    // 构造下载链接
                    var url = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                    // 创建隐藏的<a>标签并触发点击事件
                    $('<a></a>').attr('href', url).attr('download', result.msg)[0].click();
                } else {
                    $.modal.alertError(result.msg);
                }
            });
            } else {
                $.modal.alertWarning("未配置下载模板URL");
            }
        };
    </script>
     <!-- 导入区域 -->
     <script id="importTpl" type="text/template">
         <form enctype="multipart/form-data" class="mt20 mb10">
             <div class="col-xs-offset-1">
                 <input type="file" id="file" name="file"/>
                 <div class="mt10 pt5">
                     <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据
                 </div>
                 <font color="red" class="pull-left mt10">
                     提示：仅允许导入“xls”或“xlsx”格式文件！
                 </font>
             </div>
         </form>
     </script>
</body>
</html>